/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.capex.javaee.sockets;

import java.net.*;

public class UDPClient {

    public static void main(String args[]) throws Exception {
        DatagramSocket udpclientsocket = new DatagramSocket();
        InetAddress IPaddress = InetAddress.getByName("localhost");
        byte[] senddata = new byte[1024];
        byte[] receivedata = new byte[1024];
        String clientRequest = "hello my dear friend\n";
        senddata = clientRequest.getBytes();
        DatagramPacket sendPacket = new DatagramPacket(senddata, senddata.length, IPaddress, 7777);
        udpclientsocket.send(sendPacket);
        DatagramPacket receivepacket = new DatagramPacket(receivedata, receivedata.length);
        udpclientsocket.receive(receivepacket);
        String serverReply = new String(receivepacket.getData());
        System.out.println("From server:" + serverReply.trim());
    }
}
